import request from '@/utils/useRequest'
export const httpUpload = (file) => {
    let formData = new FormData()
    formData.append('file', file)
    return request({
        url: '/upload/file',
        method: 'post',
        data: formData
    })
}
const getApi = (api) => {
    return  {
        list: (data) => {
            return request({
                url: `/${api}/list`,
                params: data,
                method: 'get'
            })
        },
            page: (data) => {
            return request({
                url: `/${api}`,
                params: data,
                method: 'get'
            })
        },
            read: (id) => {
            return request({
                url: `/${api}/` + id,
                method: 'get'
            })
        },
            update: (data) => {
            return request({
                url: `/${api}/` + data.id,
                data,
                method: 'put'
            })
        },
            create: (data) => {
            return request({
                url: `/${api}`,
                data,
                method: 'post'
            })
        },
            del: (id) => {
            return request({
                url: `/${api}/` + id,
                method: 'delete'
            })
        },
    }
}
export const http = {
    login: (data) => {
        return request({
            url: '/user/login',
            data,
            method: 'post'
        })
    },
    banner: {
        ...getApi('banner')
    },
    news: {
        ...getApi('news')
    },
    user: {
        ...getApi('user')
    },
    diagnosis: {
        ...getApi('diagnosis')
    },
    color: {
        ...getApi('color')
    },
    consult: {
        ...getApi('consult')
    },
    comment: {
        ...getApi('comment')
    },
}